package cn.dlc.myapplication.adapter;

import android.bluetooth.BluetoothDevice;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import cn.dlc.myapplication.R;

/**
 * Created by John on 2018/5/17.
 */

public class BtAdapter extends SimpleRecyclerAdapter<BluetoothDevice, BtAdapter.ViewHolder> {

    @Override
    public ViewHolder createViewHolderInstance(View itemView, int viewType) {
        return new ViewHolder(itemView);
    }

    @Override
    public int getItemLayoutId(int viewType) {
        return R.layout.item_bt;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {

        BluetoothDevice item = getItem(position);
        holder.mTvName.setText(item.getName());
        holder.mTvMac.setText(item.getAddress());
    }

    @Override
    public void addData(BluetoothDevice data) {

        if (!mData.contains(data)) {
            super.addData(data);
        }
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_name)
        TextView mTvName;
        @BindView(R.id.tv_mac)
        TextView mTvMac;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
